package com.jcy_lyh.searchingsorting;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import java.util.Arrays;

public class SecondActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);

        final EditText input = findViewById(R.id.editText);
        final EditText output = findViewById(R.id.editText2);
        Button selectionSort = findViewById(R.id.button1);
        Button bubbleSort = findViewById(R.id.button2);
        Button insertionSort = findViewById(R.id.button3);
        Button ShellSort = findViewById(R.id.button4);
        Button mergeSort = findViewById(R.id.button5);
        Button quickSort = findViewById(R.id.button);

    //选择排序
    selectionSort.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String m = String.valueOf(input.getText().toString());
            String index[] = m.split(",");
            final int[] index1 = new int[index.length];
            for(int i=0;i<index.length;i++)
            {
                index1[i] = Integer.parseInt(index[i]);
            }
            Sorting a = new Sorting();
            output.setText(a.selectionSort(index1));
         }
    });
        //冒泡排序
        bubbleSort.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String m = String.valueOf(input.getText().toString());
                String index[] = m.split(",");
                final int[] index1 = new int[index.length];
                for(int i=0;i<index.length;i++)
                {
                    index1[i] = Integer.parseInt(index[i]);
                }
                Sorting a = new Sorting();
                output.setText(a.bubbleSort(index1));
            }
        });
        //插入排序
        insertionSort.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String m = String.valueOf(input.getText().toString());
                String index[] = m.split(",");
                final int[] index1 = new int[index.length];
                for(int i=0;i<index.length;i++)
                {
                    index1[i] = Integer.parseInt(index[i]);
                }
                Sorting a = new Sorting();
                output.setText(a.insertionSort(index1));
            }
        });
        //希尔排序
        ShellSort.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String m = String.valueOf(input.getText().toString());
                String index[] = m.split(",");
                final int[] index1 = new int[index.length];
                for(int i=0;i<index.length;i++)
                {
                    index1[i] = Integer.parseInt(index[i]);
                }
                Sorting a = new Sorting();
                output.setText(a.ShellSort(index1));
            }
        });
        //归并排序
        mergeSort.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String m = String.valueOf(input.getText().toString());
                String index[] = m.split(",");
                final int[] index1 = new int[index.length];
                for(int i=0;i<index.length;i++)
                {
                    index1[i] = Integer.parseInt(index[i]);
                }
                Sorting a = new Sorting();
                a.mergeSort(index1);
                output.setText(Arrays.toString(index1));
            }
        });
        //快速排序
        quickSort.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String m = String.valueOf(input.getText().toString());
                String index[] = m.split(",");
                final int[] index1 = new int[index.length];
                for(int i=0;i<index.length;i++)
                {
                    index1[i] = Integer.parseInt(index[i]);
                }
                Sorting a = new Sorting();
                a.quickSort(index1);
                output.setText(Arrays.toString(index1));
            }
        });
    }
}
